var ajax = function(method, url,param, callback) {

    var xhr = new XMLHttpRequest();
    xhr.open(method, url, true);
    
    if (method.toLocaleLowerCase()=='post' || method.toLocaleLowerCase()=='put') {
        xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded")
        xhr.send(param);
    }else {
        xhr.send();
    }

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4 && xhr.status == 200) {
            callback(JSON.parse(xhr.responseText));
        }
    }

};

var $ = function(id) {
    if (typeof id == 'string') {
        return document.getElementById(id);
    } else {
        return id; 
    }

};

var $$ = function(name) {
    if (typeof name == 'string') {
        return document.getElementsByName(name);
    }else {
        return name;
    }
};
 var getCheckedGender = function(nodelist) {
    for(var i=0;i<nodelist.length;i++) {
        if(nodelist[i].checked) {
                return nodelist[i].value;
        }
        
    }
}
var setRadioGroupChecked = function(value,nodeList) {
    for(var i=0;i<nodeList.length;i++) {
        if(nodeList[i].value == value){
            nodeList[i].checked = true;
        } 
    }

};

var getCheckedValueByHobby = function(nodeList) {
    var arr = [];
    for(var i=0;i<nodeList.length;i++) {
        if(nodeList[i].checked){
            arr.push(nodeList[i].value);
        }
    }
    return arr.join('|');
};